<template>
  <div id="resourceManagement">
    <div id="tabelTitle">
      就业管理
    </div>
    <div id="table">
      <avue-crud
        v-model="form"
        :search.sync="searchForm"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
        @selection-change="selectionChange"
      >

        <template slot="menuLeft" slot-scope="{size}">

          <el-button type="primary" :size="size" @click="rowDel()">删除</el-button>
        </template>
      </avue-crud>
    </div>

  </div>
</template>

<script>
import tableMixins from "@/mixins/tableMixin.vue"

export default {
  name: "employmentManagement",
  mixins: [tableMixins],
  data() {
    return {
      isSubmit:false,
      form: {},
      data: [],
      //访问接口前缀
      url: "yuanjiu.testnew/tn-employment",
      searchForm: {},
      // 表格参数
      tableOption: {
        border: true,
        index: false,
        indexLabel: '序号',
        indexWidth: 50,
        stripe: true,
        align: 'center',
        searchMenuSpan: 8,
        searchLabelWidth: 100,
        calcHeight: 300,
        dialogWidth: 900,
        menuWidth: 200,
        menu: true,
        menuAlign: 'center',
        refreshBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        addBtn: true,
        selection: true,
        rowKey: "id",
        emptyBtn: true,
        editBtn: true,
        viewBtn: true,
        delBtn: false,
        emptyBtnText: "重置",
        editBtnText: "修改",
        maxHeight: 645000,
        searchSize: "medium",
        column: [
          {
            label: "手机号",
            prop: "phone",
            hide:true,
            change: ({value}) => {
              if(value.length==11){
                this.$httpService.get('/yuanjiu.testnew/tn-employment/getStudentByPhoneNum?phoneNum='+value).then(res => {
                  this.form = res
                  this.isSubmit =true
                })
              }
            },
          },
          {
            prop: 'stuName',
            label: '学员名称',editDisabled:true ,addDisabled:true ,
          },
          {
            prop: 'productId',
            label: '培训类别',
            type: "select",
            dicUrl: '/yuanjiu.testnew/tn-product/listTnProduct',
            dicMethod: 'post',
            props: {
              label: 'productName',
              value: 'productId',
              res: 'result'
            }
          ,editDisabled:true ,addDisabled:true ,
          },
          {
            prop: 'className',
            label: '班级名称',editDisabled:true ,addDisabled:true ,
          }
          ,
          {
            prop: 'lecturerId',
            label: '讲师',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-admin/getUserByRoleId?roleId=17',
            props: {
              label: 'adminRealName',
              value: 'adminId',
              res: 'result'
            }
          ,editDisabled:true ,addDisabled:true ,
          }
          ,
          {
            prop: 'classManagerId',
            label: '班主任',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-admin/getUserByRoleId?roleId=16',
            props: {
              label: 'adminRealName',
              value: 'adminId',
              res: 'result'
            }
          ,editDisabled:true ,addDisabled:true ,
          },
          {
            prop: 'graduateTime',
            label: '毕业时间',
            type: "date",
            format:'yyyy-MM-dd',
            valueFormat:'yyyy-MM-dd'
            ,editDisabled:true ,addDisabled:true ,
          },
          {
            prop: 'workTime',
            label: '就业时间',
            type: "date",
            format:'yyyy-MM-dd',
            valueFormat:'yyyy-MM-dd',
            editDisabled:true ,
          } ,
          {
            prop: 'workCity',
            label: '工作地点',
          },
          {
            prop: 'company',
            label: '入职公司',
          },
          {
            prop: 'salary',
            label: '薪资',
          }
        ]
      },
      listUrl: 'pageTnEmployment',
      delUrl: "deleteList",
      updateUrl:"insertOrUpdate",
      delIdList: [],
    }
  },
  methods:{
    handleSave: function (row, done, loading) {
      if(this.isSubmit){
        this.$httpService.post("/" + this.url + "/"+this.addUrl, row).then(res => {
          this.$message.success('新增成功');
          this.getList();
          done();
          loading();
        }).catch(res=>{
          loading();
        })
      }
      else {
        this.$message.error('请输入正确手机号码查询');
        loading();
      }

    },
    //勾选获取当前数据ID
    selectionChange(list){
      // console.log(list)
      this.delIdList =[]
      list.forEach((x)=>{
        this.delIdList.push(x.empId)
      })
    },
    /**
     * 删除
     * @param row 行数据
     * @param index 行索引
     */
    rowDel: function (row) {
      if (this.delIdList.length == 0) {
        this.$message.error('请先选择数据');
      } else {
      this.$confirm('是否确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$httpService.post("/" + this.url + "/"+this.delUrl,this.delIdList).then(res => {
          this.$message.success('删除成功');
          this.getList();
        })
      })}
    },

  }
}
</script>

<style scoped>

</style>
